<template>
  <van-address-edit
    :area-list="areaList"
    show-delete
    @save="onSave"
    @delete="onDelete"
  />
</template>

<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
import axios from "axios";
import AreaList from "@/api/area";
import { addressForm } from "@/form/addressForm";
import { Toast } from "vant";

@Component
export default class AddressNew extends Vue {
  private areaList = AreaList;

  protected onSave(content: addressForm) {
    console.log(content);
    axios.post("http://localhost:8081/address/create", content).then((res) => {
      console.log(res.data);
      if (res.data.code === 0) {
        let instance = Toast("添加成功！");
        setTimeout(() => {
          instance.close();
          this.$router.push("/addressList");
        }, 1000);
      }
    });
  }
  protected onDelete() {
    history.go(-1);
  }
}
</script>
